<?php
namespace App\Sevrice;
//观察者对象主题
interface Subject{
public function regsiter(Observer $observer);

public function notify($info);
}

//张三  李四和王五
class zhangsan implements Subject{

public $observers = array();

public function regsiter(Observer $observer)
{
$this->observers[] = $observer;
}

public function notify($info)
{
foreach ($this->observers as $observer){
$observer->watch($info);
}
}
}

//观察者主题
interface Observer{
public function watch($info);
}

class lisi implements Observer{
public function watch($info)
{
echo "我是李四,我现在知道张三$info\n";
}
}

class wangwu implements Observer{
public function watch($info)
{
echo "我是王五,我现在知道张三$info\n";
}
}

$zhangsan = new zhangsan();

$zhangsan->regsiter(new lisi());

$zhangsan->regsiter(new wangwu());

$zhangsan->notify('有钱');
